package com.spddr.pmos.jpa;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.joda.time.Period;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import cn.seqdata.jpa.AbstractPersistable;

@Entity
@Table(name = "object_data_storage")
public class ObjectDataStorage extends AbstractPersistable<ObjectDataStorageId> {
	private static final long serialVersionUID = 1L;

	private ObjectType objectType;
	private Metric metric;
	
	private String tableName;

	public ObjectDataStorage() {
	}

	public ObjectDataStorage(int objectType, String metric, Period interval) {
		setId(new ObjectDataStorageId(objectType, metric, interval));
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "object_type", nullable = false, insertable = false, updatable = false)
	@JsonSerialize(using = cn.seqdata.jackson.TypeSerializer.IdName.class)
	public ObjectType getObjectType() {
		return this.objectType;
	}

	public void setObjectType(ObjectType objectType) {
		this.objectType = objectType;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "metric", nullable = false, insertable = false, updatable = false)
	@JsonSerialize(using = cn.seqdata.jackson.StringSerializer.IdName.class)
	public Metric getMetric() {
		return this.metric;
	}

	public void setMetric(Metric metric) {
		this.metric = metric;
	}

	@Column(name = "table_name")
	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

}
